package cn.liziguo.tank.collision;

import cn.liziguo.tank.constants.GameEnum;
import cn.liziguo.tank.factory.EffectsFactory;
import cn.liziguo.tank.script.BulletComponent;
import cn.liziguo.tank.script.HomeComponent;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.physics.CollisionHandler;

/**
 * @author Liziguo
 * @date 2022-07-09 21:26:11
 */
public class BulletHomeCollisionHandler extends CollisionHandler {

    public BulletHomeCollisionHandler() {
        super(GameEnum.BULLET, GameEnum.HOME);
    }

    @Override
    protected void onCollisionBegin(Entity bullet, Entity home) {
        // 如果子弹同时碰撞home和其他对象 则忽略本次碰撞
//        List<Entity> entityList = FXGL.getGameWorld().getGroup(GameEnum.PLAYER, GameEnum.ENEMY, GameEnum.BRICK, GameEnum.STONE, GameEnum.BULLET).getEntitiesCopy();
//        for (Entity entity : entityList) {
//            if (bullet != entity && bullet.isColliding(entity)) {
//                if (entity.isType(GameEnum.BULLET)) {
//                    if (bullet.getObject(PropertyConst.CAMP) != entity.getObject(PropertyConst.CAMP)) {
//                        return;
//                    }
//                }
//                return;
//            }
//        }
        EffectsFactory.createBoom(home.getCenter());
        // 销毁基地
        home.getComponent(HomeComponent.class).destroy();
        BulletComponent.onRemove(bullet);
    }
}
